import { Query } from '../utils/Query'
import { DOCMAP } from '../constants'
export const displayLay = (e, map) => {
  if (e == 0) {
    map.getLayers().getArray()[2].setLayerStatus('0,1', 'show')
    map.getLayers().getArray()[2].setLayerStatus('2,3,4', 'hide')
  }
  if (e == 1) {
    map.getLayers().getArray()[2].setLayerStatus('1', 'show')
    map.getLayers().getArray()[2].setLayerStatus('0,2,3,4', 'hide')
  }
  if (e == 2) {
    map.getLayers().getArray()[2].setLayerStatus('1,2', 'show')
    map.getLayers().getArray()[2].setLayerStatus('0,3,4', 'hide')
  }
  if (e == 3) {
    map.getLayers().getArray()[2].setLayerStatus('1,3', 'show')
    map.getLayers().getArray()[2].setLayerStatus('0,2,4', 'hide')
  }
  if (e == 4) {
    map.getLayers().getArray()[2].setLayerStatus('1,4', 'show')
    map.getLayers().getArray()[2].setLayerStatus('0,2,3', 'hide')
  }
  if (e == 5) {
    map.getLayers().getArray()[2].setLayerStatus('0,1,2,3,4', 'show')
  }
  if (e == 6) {
    map.getLayers().getArray()[2].setLayerStatus('0,1,2,3,4', 'hide')
  }
  if (e == 7) {
    let roadFlow = [
      { where: ' 车流量<=1300', color: '#4fd27d' },
      { where: '车流量>1300 and 车流量<=1500', color: '#ffd045' },
      { where: '车流量>1500 and 车流量<=1700', color: '#e80e0e' },
      { where: '车流量>1700 and 车流量<=2100', color: '#b50000' },
    ]
    let service = { docName: DOCMAP, layerId: 1 }
    roadFlow.map((item) => {
      Query.queryBySql({
        where: item.where,
        service,
        callback: (res) => getBack(res, item),
      })
      const getBack = (res) => {
        var format = new Zondy.Format.PolygonJSON()
        //将MapGIS要素JSON反序列化为ol.Feature类型数组
        var features = format.read(res)
        // console.log(features)
        //实例化一个矢量图层drawLayerr用于高亮显示结果
        var drawSource = new ol.source.Vector({
          wrapX: false,
        })
        drawSource.addFeatures(features)
        var drawLayer = new ol.layer.Vector({
          source: drawSource,
          style: new ol.style.Style({
            //边线样式
            stroke: new ol.style.Stroke({
              color: item.color,
              width: 3,
            }),
          }),
        })
        map.addLayer(drawLayer)
      }
    })
  }
}
